from wtforms import Form,StringField
from wtforms.validators import DataRequired, Regexp, ValidationError
from model.userdb import User

class UserForm(Form) :
    username = StringField(validators=[DataRequired()])
    password = StringField(validators=[DataRequired(), Regexp(r"\w{6,18}",message="密码不符合要求")])

    def validate_username(self, value):
        if User.query.filter_by(username=value.data).first():
            raise ValidationError("用户已存在")


